<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false"%>
<%@ page import="Dao.usersDAO" %>
<%@ page import="JavaBean.users" %>
<%@ page import="Dao.userBooksDao" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>加入书架</title>
</head>
<body>

<%
    request.setCharacterEncoding("utf-8");
    //获取goods.jsp页面传来的userID
    HttpSession session1 = request.getSession();
    users login_user = (users) session1.getAttribute("login_user");

    int userID = login_user.getId();

    request.setAttribute("login_user",login_user);



    //获取goods.jps页面传来的bookID
    String bookID = request.getParameter("bookID");
    System.out.println("bookID = " + bookID);
    //开始操作数据库,将userID和bookID进行绑定
    userBooksDao dao = new userBooksDao();
    //绑定是否成功,有一个返回值
    int i = dao.insert(userID,bookID);
    pageContext.setAttribute("i",i);

    System.out.println("i = " + i);
%>

<jsp:useBean id="books" class="JavaBean.Book" scope="request"></jsp:useBean>
<jsp:setProperty name="books" property="*"></jsp:setProperty>

<c:choose>

    <c:when test="${i==1}">
        <!--加入书架成功就直接调换至书架界面,若要返回就点击返回按钮返回至goods.jsp页面-->
        <script language='javascript'>alert('加入书架成功');window.location.href='userBooksManager.jsp';</script>
    </c:when>
    <c:when test="${i==0}">
        <script language='javascript'>alert('加入书架失败');window.location.href='userBooksManager.jsp?';</script>
    </c:when>
</c:choose>
</body>
</html>
